package com.lanou.utp.utils;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;

/**
 * @author MaQingYun
 */
public class CalendarUtils {

    public static final String SEARCH_START_DATE = "searchStartDate";
    public static final String SEARCH_END_DATE = "searchEndDate";

    public static HashMap<String, Date> teachingCalendar(Integer searchdateId) {
        SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        Date searchStartDate = null;
        Date searchEndDate = null;
        //获取本周日期
        if (searchdateId == 1) {
            cal.add(Calendar.WEEK_OF_MONTH, 0);
            cal.set(Calendar.DAY_OF_WEEK, 2);
            searchStartDate =Date.valueOf(simpleDate.format(cal.getTime())) ;
            cal2.set(Calendar.DAY_OF_WEEK, cal.getActualMaximum(Calendar.DAY_OF_WEEK));
            cal2.add(Calendar.DAY_OF_WEEK, 2);
            searchEndDate = Date.valueOf(simpleDate.format(cal2.getTime()));
        }
        else if (searchdateId == 2){
            cal.add(Calendar.WEEK_OF_MONTH, -1);
            cal.set(Calendar.DAY_OF_WEEK, 2);
            searchStartDate =Date.valueOf(simpleDate.format(cal.getTime())) ;
            cal2.add(Calendar.WEEK_OF_MONTH, 0);
            cal2.set(Calendar.DAY_OF_WEEK, 2);
//            cal2.set(Calendar.DAY_OF_WEEK, cal.getActualMaximum(Calendar.DAY_OF_WEEK));
//            cal2.add(Calendar.DAY_OF_WEEK, -6);
            searchEndDate = Date.valueOf(simpleDate.format(cal2.getTime()));
        }
        else if (searchdateId == 3){
            cal.add(Calendar.MONTH, 0);
            cal.set(Calendar.DAY_OF_MONTH, 1);
            searchStartDate = Date.valueOf(simpleDate.format(cal.getTime()));
            cal2.add(Calendar.MONTH, 1);
            cal2.set(Calendar.DAY_OF_MONTH, 1);
            searchEndDate = Date.valueOf(simpleDate.format(cal2.getTime()));
        }
        else if (searchdateId == 4){
            cal.add(Calendar.MONTH, -1);
            cal.set(Calendar.DAY_OF_MONTH, 1);
            searchStartDate = Date.valueOf(simpleDate.format(cal.getTime()));
            cal2.add(Calendar.MONTH, 0);
            cal2.set(Calendar.DAY_OF_MONTH, 1);
            searchEndDate = Date.valueOf(simpleDate.format(cal2.getTime()));
        }
        else if (searchdateId == 5){
            String firstDay = String.valueOf(cal.get(Calendar.YEAR))+"-01-01";
            searchStartDate =Date.valueOf(firstDay) ;
            String lastDay = String.valueOf(cal.get(Calendar.YEAR)+1)+"-01-01";
            searchEndDate =Date.valueOf(lastDay) ;
        } else if (searchdateId == 6){
            String lastYearFday = String.valueOf(cal.get(Calendar.YEAR) - 1)+"-01-01";
            searchStartDate =Date.valueOf(lastYearFday) ;
            String lastYearLday = String.valueOf(cal.get(Calendar.YEAR))+"-01-01";
            searchEndDate =Date.valueOf(lastYearLday) ;
        }
        HashMap<String, Date> map = new HashMap<>();
        map.put(SEARCH_START_DATE,searchStartDate);
        map.put(SEARCH_END_DATE,searchEndDate);
        System.out.println("map = " + map);
        return map;
    }


}
